// 文档模块相关类型定义

// 文档来源信息
export interface DocSource {
  name: string          // 来源名称，如 "Cursor 官方文档"
  url: string          // 原始文档URL
  version?: string     // 文档版本
  lastSync?: string    // 最后同步时间
  language?: string    // 文档语言
}

// 文档内容类型
export type DocContentType = 'original' | 'documentation' | 'translation' | 'reference'

// 文档课程扩展类型
export interface DocLesson {
  id: number
  categoryId: number
  title: string
  slug: string
  content: string
  excerpt?: string
  coverImage?: string
  difficulty: 'beginner' | 'intermediate' | 'advanced'
  duration?: number
  sortOrder: number
  isPublished: boolean
  viewCount: number
  
  // 文档特有字段
  contentType: DocContentType
  source?: DocSource
  originalUrl?: string
  lastSyncAt?: string
  needsUpdate?: boolean
  
  // 文档元数据
  docMeta?: {
    keywords?: string[]
    platform?: string[]    // Windows, Mac, Linux
    features?: string[]    // Tab, Chat, Agent 等
    languages?: string[]   // 支持的编程语言
  }
  
  category?: DocCategory
  tags?: DocTag[]
  createdAt: string
  updatedAt: string
}

// 文档分类扩展类型
export interface DocCategory {
  id: number
  name: string
  slug: string
  description?: string
  icon?: string
  sortOrder: number
  parentId?: number | null
  
  // 文档特有字段
  isDocCategory: boolean
  docSource?: string     // 文档来源标识
  isActive?: boolean     // 是否启用
  lessonsCount?: number  // 文档数量
  
  parent?: DocCategory | null
  children?: DocCategory[]
  lessons?: DocLesson[]
}

// 文档标签类型
export interface DocTag {
  id: number
  name: string
  slug: string
  type: 'feature' | 'platform' | 'language' | 'general'
  color?: string
  usageCount?: number
}

// 文档导入配置
export interface DocImportConfig {
  source: string              // 数据源标识
  baseUrl: string            // 基础URL
  selectors: {               // DOM选择器配置
    title?: string
    content?: string
    navigation?: string
    code?: string
  }
  delay?: number             // 请求延迟(ms)
  batchSize?: number         // 批量处理大小
  imageDownload?: boolean    // 是否下载图片
  imagePrefix?: string       // 图片前缀
}

// 文档导入任务
export interface DocImportTask {
  id?: number
  source: string
  status: 'pending' | 'running' | 'completed' | 'failed'
  totalPages?: number
  processedPages?: number
  startedAt?: string
  completedAt?: string
  error?: string
  logs?: DocImportLog[]
}

// 文档导入日志
export interface DocImportLog {
  timestamp: string
  level: 'info' | 'warning' | 'error'
  message: string
  details?: any
}

// 文档搜索参数
export interface DocSearchParams {
  keyword?: string
  contentType?: DocContentType
  source?: string
  platform?: string[]
  language?: string[]
  difficulty?: string
  categoryId?: number
  tagIds?: number[]
  page?: number
  limit?: number
  sortBy?: 'relevance' | 'date' | 'views'
}

// 文档统计信息
export interface DocStats {
  totalDocs: number
  bySource: Record<string, number>
  byContentType: Record<DocContentType, number>
  byDifficulty: Record<string, number>
  popularTags: Array<{
    name: string
    count: number
  }>
  recentlyUpdated: DocLesson[]
}

// 文档导入映射规则
export interface DocMappingRule {
  source: string
  patterns: {
    category?: RegExp | string
    difficulty?: RegExp | string
    tags?: RegExp | string
  }
  transforms: {
    title?: (text: string) => string
    content?: (html: string) => string
    excerpt?: (content: string) => string
  }
}

// 文档版本信息
export interface DocVersion {
  docId: number
  version: string
  content: string
  changedBy?: string
  changedAt: string
  changeLog?: string
} 